load("@rules_cc//cc:defs.bzl", "cc_test")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

# Example of the cmake_external target built with Bazel-built dependency
cmake(
    name = "cmake_libb",
    cache_entries = {
        # CMake's find_package wants to find cmake config for liba,
        # which we do not have -> disable search
        "CMAKE_DISABLE_FIND_PACKAGE_LIBA": "True",
        # as currently we copy all libraries, built with Bazel, into $EXT_BUILD_DEPS/lib
        # and the headers into $EXT_BUILD_DEPS/include
        "LIBA_DIR": "$EXT_BUILD_DEPS",
    },
    generate_args = ["-GNinja"],
    lib_source = "//cmake_with_bazel_transitive/libb:b_srcs",
    out_static_libs = select({
        "//:windows": ["libb.lib"],
        "//conditions:default": ["libb.a"],
    }),
    # This library is with public visibility, we can reuse it here.
    deps = ["//cmake_synthetic/liba:lib_a_bazel"],
)

# And cc_test built with cmake_external dependency and transitive Bazel dependency
cc_test(
    name = "test",
    srcs = [
        "test_libb.cpp",
    ],
    deps = [
        # liba should come from transitive dependencies
        ":cmake_libb",
    ],
)
